package com.itheima.d1_getAnnotation;

import org.junit.jupiter.api.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * 解析注解的内容
 */
public class AnnotationDemo3 {
    @Test
    public void parseClass() throws NoSuchMethodException {
        //1.获取对象
        Class c = BookSore.class;
        Method m = c.getDeclaredMethod("test");
        //2.判断该类上是否存在注解
        if(c.isAnnotationPresent(Book.class)){
            Book book = (Book) c.getDeclaredAnnotation(Book.class);
            System.out.println(book.value());
            System.out.println(book.price());
            System.out.println(Arrays.toString(book.authors()));
        }

        //3.判断方法上的注解
        if(m.isAnnotationPresent(Book.class)){
            Book book1 = (Book) m.getDeclaredAnnotation(Book.class);
            System.out.println(book1.value());
            System.out.println(book1.price());
            System.out.println(Arrays.toString(book1.authors()));
        }
    }
}
@Book(value = "《围城》",price = 123,authors = {"钱钟书"})
class BookSore{
    @Book(value = "《龙族》",price = 80,authors = {"江南"})
    public void test(){
    }

}
